
function getE(name) {
    if (document.getElementById)
        var elem = document.getElementById(name);
    else if (document.all)
        var elem = document.all[name];
    else if (document.layers)
        var elem = document.layers[name];
    return elem;
}

function OpenWindow(query, w, h, scroll) {
    var l = (screen.width - w) / 2;
    var t = (screen.height - h) / 2;

    winprops = 'resizable=0, height=' + h + ',width=' + w + ',top=' + t + ',left=' + l + 'w';
    if (scroll) winprops += ',scrollbars=1';
    var f = window.open(query, "_blank", winprops);
}

(function ($) {
    $.fn.hoverIntent = function (f, g) {
        // default configuration options
        var cfg = {
            sensitivity: 7,
            interval: 100,
            timeout: 0
        };
        // override configuration options with user supplied object
        cfg = $.extend(cfg, g ? { over: f, out: g} : f);

        // instantiate variables
        // cX, cY = current X and Y position of mouse, updated by mousemove event
        // pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
        var cX, cY, pX, pY;

        // A private function for getting mouse position
        var track = function (ev) {
            cX = ev.pageX;
            cY = ev.pageY;
        };

        // A private function for comparing current and previous mouse position
        var compare = function (ev, ob) {
            ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
            // compare mouse positions to see if they've crossed the threshold
            if ((Math.abs(pX - cX) + Math.abs(pY - cY)) < cfg.sensitivity) {
                $(ob).unbind("mousemove", track);
                // set hoverIntent state to true (so mouseOut can be called)
                ob.hoverIntent_s = 1;
                return cfg.over.apply(ob, [ev]);
            } else {
                // set previous coordinates for next time
                pX = cX; pY = cY;
                // use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
                ob.hoverIntent_t = setTimeout(function () { compare(ev, ob); }, cfg.interval);
            }
        };

        // A private function for delaying the mouseOut function
        var delay = function (ev, ob) {
            ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
            ob.hoverIntent_s = 0;
            return cfg.out.apply(ob, [ev]);
        };

        // A private function for handling mouse 'hovering'
        var handleHover = function (e) {
            // copy objects to be passed into t (required for event object to be passed in IE)
            var ev = jQuery.extend({}, e);
            var ob = this;

            // cancel hoverIntent timer if it exists
            if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }

            // if e.type == "mouseenter"
            if (e.type == "mouseenter") {
                // set "previous" X and Y position based on initial entry point
                pX = ev.pageX; pY = ev.pageY;
                // update "current" X and Y position based on mousemove
                $(ob).bind("mousemove", track);
                // start polling interval (self-calling timeout) to compare mouse coordinates over time
                if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout(function () { compare(ev, ob); }, cfg.interval); }

                // else e.type == "mouseleave"
            } else {
                // unbind expensive mousemove event
                $(ob).unbind("mousemove", track);
                // if hoverIntent state is true, then call the mouseOut function after the specified delay
                if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout(function () { delay(ev, ob); }, cfg.timeout); }
            }
        };

        // bind the function to the two event listeners
        return this.bind('mouseenter', handleHover).bind('mouseleave', handleHover);
    };
})(jQuery);

(function ($) {
    $.fn.extend({
        mainMenu: function () {
            return this.each(
                function () {
                    var menu = $(this);
                    var timeout = null;

                    if (menu.is('ul')) {
                        // get the parent container
                        var parent = menu.parent();
                        // get all the children (first level li's)
                        var menuItems = menu.children();
                        menuItems.each(function () {
                            var menuItem = $(this);

                            var subMenuItems = menuItem.children('ul').children();

                            if (subMenuItems.length > 0) {
                                var movedItemsCount = 0;
                                var currentSubList = null;
                                var container = $('<div/>').addClass('flyout').appendTo(menuItem);

                                do {
                                    if (movedItemsCount % 4 == 0) {
                                        currentSubList = $('<ul/>').appendTo(container);
                                    }
                                    subMenuItems.eq(movedItemsCount).appendTo(currentSubList).find('a').hover(
                                        function () { $(this).animate({ paddingLeft: 9 }); },
                                        function () { $(this).animate({ paddingLeft: 0 }); }
                                    );

                                    movedItemsCount++;
                                }

                                // wait
                                while (movedItemsCount < subMenuItems.length);

                                menuItem.children('ul').remove();

                                menuItem.hoverIntent({
                                    sensitivity: 3,
                                    interval: 100,
                                    timeout: 500,
                                    over: function () {
                                        var containers = menuItems.children('div').filter(':visible');
                                        clearTimeout(timeout);

                                        if (containers.length == 0) {
                                            container.slideDown();
                                        }
                                        else {
                                            containers.hide();
                                            container.show();
                                        }

                                        menuItems.removeClass('hover');
                                        menuItem.addClass('hover');
                                    },
                                    out: function () {
                                        container.slideUp();
                                        menuItem.removeClass('hover');
                                    }
                                });
                                container.hover(
                                    function () { clearTimeout(timeout); menuItem.addClass('hover'); },
                                    function () {
                                        timeout = setTimeout(
                                            function () {
                                                container.slideUp();
                                                menuItem.removeClass('hover');
                                            },
                                        500);
                                    }
                                );
                            } else {
                                menuItem.hoverIntent({
                                    interval: 100,
                                    timeout: 500,
                                    over: function () {
                                        menuItems.removeClass('hover');
                                        menuItem.addClass('hover');

                                        menuItems.children('div').hide();
                                    },
                                    out: function () {
                                        menuItem.removeClass('hover');
                                    }
                                });
                                var flyouts = menuItem.children('div.flyout');
                                if (flyouts.length > 0) {
                                    var flyout = $(flyouts[0]);

                                    menuItem.hoverIntent({
                                        interval: 100,
                                        timeout: 500,
                                        over: function () {
                                            clearTimeout(timeout);
                                            flyout.slideDown();
                                            menuItems.removeClass('hover');
                                            menuItem.addClass('hover');
                                        },
                                        out: function () {
                                            flyout.slideUp();
                                            menuItem.removeClass('hover');
                                        }
                                    });
                                }
                            }
                        }
                        );
                    }
                }
            );
        }
    }
);
}
)(jQuery);

jQuery(document).ready(function ($) {

    $('.menu').mainMenu();

    function activateTab($tab) {
        var $activeTab = $tab.closest('dl').find('a.active'),
				contentLocation = $tab.attr("href") + 'Tab';

        // Strip off the current url that IE adds
        contentLocation = contentLocation.replace(/^.+#/, '#');

        //Make Tab Active
        $activeTab.removeClass('active');
        $tab.addClass('active');

        //Show Tab Content
        $(contentLocation).closest('.tabs-content').children('li').hide();
        $(contentLocation).css('display', 'block');
    }

    $('dl.tabs').each(function () {
        //Get all tabs
        var tabs = $(this).children('dd').children('a');
        tabs.click(function (e) {
            activateTab($(this));
        });
    });

    if (window.location.hash) {
        activateTab($('a[href="' + window.location.hash + '"]'));
    }
});